
package todolist.logic.parser;

import todolist.entity.TaskFieldType;
import todolist.personalization.TaskFieldCustomizer;

/**
 * Parser of field of Task to be Edited.
 * @author Ivan
 */
public class EditFieldParser {
	
	private GenericParser _objGP;
	
	public EditFieldParser() {
		_objGP = new GenericParser();
	}

	/**
	 * Tries to parse a String containing field of Task to be edited
	 * Valid fields for editing are {Task Name, Date/Time, Priority, Comments, Reminder Offset}.
	 */
	public TaskFieldType parseEditField(String pstrInput) {
		// no-match conditions
		if (pstrInput == null)
			return null;
		pstrInput = pstrInput.trim();
		if (pstrInput.length() == 0)
			return null;
		// parse input
		if (_objGP.findMatch(TaskFieldCustomizer.getInstance().getInputFieldTaskName(), pstrInput) != null)
			return TaskFieldType.TASK_FIELD_TASKNAME;
		if (_objGP.findMatch(TaskFieldCustomizer.getInstance().getInputFieldDT(), pstrInput) != null)
			return TaskFieldType.TASK_FIELD_DT;
		if (_objGP.findMatch(TaskFieldCustomizer.getInstance().getInputFieldPriority(), pstrInput) != null)
			return TaskFieldType.TASK_FIELD_PRIORITY;
		if (_objGP.findMatch(TaskFieldCustomizer.getInstance().getInputFieldTaskComments(), pstrInput) != null)
			return TaskFieldType.TASK_FIELD_COMMENTS;
		if (_objGP.findMatch(TaskFieldCustomizer.getInstance().getInputFieldReminder(), pstrInput) != null)
			return TaskFieldType.TASK_FIELD_REMINDER;
		return null; // if no match
	}
	
}
